#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using UTable.Input;
using UTable.Input.MultiTouch;
using UTable.Objects;
using UTable.Objects.Controls;

namespace UTable.Tests
{
	/// <summary>
	/// Interaction logic for UPopupTest.xaml
	/// </summary>
	public partial class UPopupTest : UObject
	{
		public UPopupTest()
		{
			InitializeComponent();
			this.MyPopup.PlaceTarget = this.ShowButton;
		}

		private void ShowButton_Checked(object sender, RoutedEventArgs e)
		{
			if (this.IsLoaded)
			{
				LayoutPopup();
				this.MyPopup.IsOpen = true;
			}
		}

		private void ShowButton_Unchecked(object sender, RoutedEventArgs e)
		{
			if (this.IsLoaded)
			{
				this.MyPopup.IsOpen = false;
			}
		}

		private void LayoutPopup()
		{
			switch (DirectionBox.SelectedIndex)
			{
				case 0:
					this.MyPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Top;
					break;
				case 1:
					this.MyPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Left;
					break;
				case 2:
					this.MyPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
					break;
				case 3:
					this.MyPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Right;
					break;
				case 4:
					this.MyPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Relative;
					this.MyPopup.HorizontalOffset = OffsetXSlider.Value;
					this.MyPopup.VerticalOffset = OffsetYSlider.Value;
					break;
				case 5:
					this.MyPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Absolute;
					this.MyPopup.HorizontalOffset = OffsetXSlider.Value;
					this.MyPopup.VerticalOffset = OffsetYSlider.Value;
					break;
			}
		}

		private void DirectionBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (IsLoaded)
			{
				LayoutPopup();
				MyPopup.PositionPopup();
			}
		}

		private void OffsetXSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
		{
			if (IsLoaded)
			{
				LayoutPopup();
				MyPopup.PositionPopup();
			}
		}

		private void OffsetYSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
		{
			if (IsLoaded)
			{
				LayoutPopup();
				MyPopup.PositionPopup();
			}
		}
	}
}
